package com.jd.mapper;

import com.jd.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.List;

/**
 * <p>
 * 平台用户 Mapper 接口
 * </p>
 *
 * @author wangshuping
 * @since 2021-11-15
 */
public interface UserMapper extends BaseMapper<User> {


    @Select("SELECT `id` ,`username`, `password`, `status` FROM t_user WHERE username = #{username} ")
    User getCommonUserByUsername(String username);

    @Select("SELECT `id` ,`username`, `password`, `status` FROM t_user WHERE username = #{username} ")
    User getAdminUserByUsername(String username);

    @Select("select `name` from t_resource")
    List<String> getAllResources();

//    @Select("select `code` from t_role tr left join t_user_role tur on tr.id=tur.role_id where tur.user_id=#{userId}")
    @Select("select `code` from t_role tr left join t_user_role tur on tr.id=tur.role_id where tur.user_id=#{userId} and tr.`code`=#{adminRole}")
    String selectRoleCode(@Param("userId")Long userId,@Param("adminRole") String adminRole);

    @Select("select t_resource.`name` from t_resource   LEFT JOIN t_role_resource  on t_resource.id=t_role_resource.resource_id" +
            " LEFT JOIN t_role   on t_role_resource.role_id=t_role.id " +
            " LEFT JOIN t_user_role on t_user_role.role_id=t_role.id " +
            " WHERE t_user_role.user_id=#{userId} ")
    List<String> getResourcesByUserId(Long userId);
}
